﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;

public class CardMember : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerDownHandler, IPointerUpHandler
{
    public bool used = false;
    private GameObject cardMember;
    private CardItem cardItem;
    private GameObject card;

    private void Start()
    {
        cardMember = this.gameObject;
    }

    public void InitCardMember(CardItem _cardItem, GameObject _card)
    {
        used = true;
        cardItem = _cardItem;
        card = _card;
        cardMember.transform.GetComponent<Image>().sprite = Resources.Load(_cardItem.boxSprite, typeof(Sprite)) as Sprite;
    }

    public void OnPointerEnter(PointerEventData eventData)
    {
        if (used)
        {
            card.SetActive(true);
        }
    }

    public void OnPointerExit(PointerEventData eventData)
    {
        if (used)
        {
            card.SetActive(false);
        }
    }

    public void OnPointerDown(PointerEventData eventData)
    {
        //右键
        if (eventData.button == PointerEventData.InputButton.Right)
        {

        }
        //左键
        else if (eventData.button == PointerEventData.InputButton.Left)
        {
            if (used)
            {
                SkillManager.AddCurrentSkill(cardItem.id);

                //使用了重置状态
                used = false;
                cardMember.transform.GetComponent<Image>().sprite = null;
                cardItem = null;
                Destroy(card);
                card = null;
            }
        }
    }

    public void OnPointerUp(PointerEventData eventData)
    {
        
    }
}
